/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tmPHA;

import ants.Constantes;
import ants.Perspective;
import java.io.*;
import java.awt.Point;
import java.util.Hashtable;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.awt.Point;
import java.io.IOException;

/**
 *
 * @author Angel
 */
public class Mapa_HAP {
    
    final int wallfix = 2;
    final int offset  = 1;
    int w;
    int h;
    int[] maxAntsT;
    Celda_HAP[][] cells;
    
    public Mapa_HAP(int m,int n)throws IOException{
        maxAntsT = new int[3];
        w = m;
        h = n;//definimos el tama�o del mapa
        cells = new Celda_HAP[h+wallfix][w+wallfix];//creamos la matriz de celdas
        for(int i = 0; i < (w+wallfix); i++){//rellenamos los bordes inferior y superior
            cells[0][i] = new Celda_HAP();
            cells[h+offset][i] = new Celda_HAP();
            cells[0][i].tipo = Constantes.obstaculo;
            cells[h+offset][i].tipo = Constantes.obstaculo;
        }
        for(int i = 0; i < (h+wallfix); i++){//rellenamos los bordes laterales
            cells[i][0] = new Celda_HAP();
            cells[i][w+offset] = new Celda_HAP();
            cells[i][0].tipo = Constantes.obstaculo;
            cells[i][w+offset].tipo = Constantes.obstaculo;
        }
        for(int i = offset; i < (h+offset); i++){        //rellenamos el mapa
            for(int j = offset; j < (w+offset); j++){
                cells[i][j] = new Celda_HAP();
                cells[i][j].tipo = Constantes.libre;
            }
        }   
    }
    public void printMapa(){
        for(int i = 0; i < (h+wallfix); i++){
            for(int j = 0; j < (w+wallfix); j++){
                if(cells[i][j].comida){
                    System.out.print("(C)");
                }else if(cells[i][j].ants.size()>0){
                    System.out.print("("+cells[i][j].tipo+")");
                }else{
                System.out.print("<"+cells[i][j].tipo+">");
                }
                
            }
            System.out.println();
        }
        System.out.println();
    }
    public void setHormigero(Point h){
        cells[h.x][h.y].tipo=2;
    }
    public Celda_HAP getCelda(int x, int y){
        return cells[x][y];
    }
    public void setCelda(Celda_HAP cell, int x, int y, Perspective p){
        cells[x][y] = cell;
        if(x==1 && y==1){
            System.out.println("HERE");
        }
    }
    public Celda_HAP[][] getMap(){
        return cells;
    }   
    void Evaporar_feromonas(){
        for(int i = 0; i < (h+wallfix); i++){
            for(int j = 0; j < (w+wallfix); j++){
                cells[i][j].removefCE();
                if(cells[i][j].getfCE()<0.001){
                    cells[i][j].fCE=0;
                }
                cells[i][j].removefCC();
                if(cells[i][j].getfCC()<0.001){
                    cells[i][j].fCC=0;
                }
                cells[i][j].removefCH();
                if(cells[i][j].getfCH()<0.001){
                    cells[i][j].fCH=0;
                }
            }
            System.out.println();
        }  
    }
    float[][] Feromonas_1(int x, int y){
        float[][] explora = new float[3][3];
        explora[0][0]=cells[y-1][x-1].fCE;
        explora[0][1]=cells[y-1][x].fCE;
        explora[0][2]=cells[y-1][x+1].fCE;
        explora[1][0]=cells[y][x-1].fCE;
        explora[1][1]=cells[y][x].fCE;
        explora[1][2]=cells[y][x+1].fCE;
        explora[2][0]=cells[y+1][x-1].fCE;
        explora[2][1]=cells[y][x].fCE;
        explora[2][2]=cells[y+1][x+1].fCE;
        return explora;
    }
    float[][] Feromonas_2(int x, int y){
        float[][] explora = new float[3][3];
        explora[0][0]=cells[y-1][x-1].fCC;
        explora[0][1]=cells[y-1][x].fCC;
        explora[0][2]=cells[y-1][x+1].fCC;
        explora[1][0]=cells[y][x-1].fCC;
        explora[1][1]=cells[y][x].fCC;
        explora[1][2]=cells[y][x+1].fCC;
        explora[2][0]=cells[y+1][x-1].fCC;
        explora[2][1]=cells[y][x].fCC;
        explora[2][2]=cells[y+1][x+1].fCC;
        return explora;
    }
    float[][] Feromonas_3(int x, int y){
        float[][] explora = new float[3][3];
        explora[0][0]=cells[y-1][x-1].fCH;
        explora[0][1]=cells[y-1][x].fCH;
        explora[0][2]=cells[y-1][x+1].fCH;
        explora[1][0]=cells[y][x-1].fCH;
        explora[1][1]=cells[y][x].fCH;
        explora[1][2]=cells[y][x+1].fCH;
        explora[2][0]=cells[y+1][x-1].fCH;
        explora[2][1]=cells[y][x].fCH;
        explora[2][2]=cells[y+1][x+1].fCH;
        return explora;
    }
}
